// ignore_for_file: prefer_interpolation_to_compose_strings, unnecessary_string_interpolations
import 'package:flutter_kit_plus/flutter_kit.dart';

const write_service = 'FFE0';
const write_char = 'FFE1';

const read_service = 'FFD0';
const read_uuid = 'FFD4';

class SendData {
  static List<int> getBytes(String tag, var data) {
    List<int> bytes = [];
    switch (tag) {
      case '亮度':
      case '声控亮度':
        bytes = [0x7B, 0xFF, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xBF];
        bytes[4] = data; //亮度(1-100)
        bytes[5] = tag == '亮度' ? 0x00 : 0x01;
      case '速度':
        bytes = [0x7B, 0xFF, 0x02, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xBF];
        bytes[3] = data as int; //速度(1-100)
      case 'RGB模式':
        bytes = [0x7B, 0xFF, 0x03, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xBF];
        bytes[3] = (data as int); //模式号(1-255)
      case 'RGB开关':
        bytes = [0x7B, 0xFF, 0x04, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xBF];
        bytes[3] = (data as bool) ? 0x01 : 0x00; //参数(0/关，1/开)
      case '单色开关':
        bytes = [0x7B, 0xFF, 0x04, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xBF];
        bytes[3] = (data as bool) ? 0x03 : 0x02; //参数(2/关，3/开)
      case '通道开关':
        bytes = [0x7B, 0xFF, 0x04, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xBF];
        bytes[3] = (data as bool) ? 0x05 : 0x04; //参数(4/关，5/开)
      case 'RGB排序':
        //像素点默认是200
        //1-RGB  2-RBG  3-GRB  4-GBR  5-BRG  6-BGR  7-RGBW  8-RBGW  9-GRBW  10-GBRW  11-BRGW  12-BGRW
        bytes = [0x7B, 0xFF, 0x05, 0x04, 0x00, 0xC8, 0xFF, 0xFF, 0xBF];
        var list = (data as List<int>);
        bytes[4] = (list[0] >> 8) & 0xFF; //点数高8位
        bytes[5] = list[0] & 0xFF; //点数低8位
        bytes[6] = list[1]; //RGB顺序
      case '暂停':
        bytes = [0x7B, 0xFF, 0x06, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xBF];
        bytes[3] = (data as bool) ? 0x01 : 0x00;
      case 'RGB色盘':
        bytes = [0x7B, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xBF];
        bytes[3] = (data as List<int>)[0]; //R(0-255)
        bytes[4] = data[1]; //G(0-255)
        bytes[5] = data[2]; //B(0-255)
      case '自定义颜色':
        bytes = [0x7B, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xBF];
        bytes[3] = (data as List<int>)[0]; //R(0-255)
        bytes[4] = data[1]; //G(0-255)
        bytes[5] = data[2]; //B(0-255)
        bytes[6] = data[3]; //参数A-01代表的是自定义,—02表示删除颜色RGB发0,-03代表音乐麦克风选择颜色,04代表音乐麦克风删除颜色
        bytes[7] = data[4]; //参数B代表的是第几个格的颜色。
      case 'RGB亮度':
        bytes = [0x7B, 0xFF, 0x08, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xBF];
        bytes[3] = (data as List<int>)[0]; //1-R 2-G 3-B
        bytes[4] = data[1]; //亮度0-32
        bytes[5] = data[2]; //亮度0-100
      case '声控模式':
        bytes = [0x7B, 0xFF, 0x0B, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xBF];
        bytes[3] = data; //模式号(1-255)
      // bytes[4] = data[1]; //参数(0-1) 参数00代表声控模式调节；01代表音乐和麦克风模式调节
      case '声控灵敏度':
        bytes = [0x7B, 0xFF, 0x0C, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xBF];
        bytes[3] = data; //灵敏度(1-100)
      // bytes[4] = data[1]; //参数(0-1) 参数00代表声控调灵明度；01代表音乐和麦克风调灵明度
      case '自定义方向':
        bytes = [0x7B, 0xFF, 0x0D, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xBF];
        bytes[3] = data; //0x00正/01 反
      case '自定义换色':
        bytes = [0x7B, 0xFF, 0x0E, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xBF];
        bytes[1] = (data as List<int>)[0]; //第几个颜色
        // bytes[3] = data[1];//（音乐和麦克风自定义换色fe；自定义换色fd
        bytes[4] = data[1]; //R
        bytes[5] = data[2]; //G
        bytes[6] = data[3]; //B
        bytes[7] = data[4]; //颜色个数
      case '自定义循环':
        bytes = [0x7B, 0xFF, 0x0F, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xBF];
      case '自定义模式':
        bytes = [0x7B, 0xFF, 0x13, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xBF];
        bytes[3] = data; //（00：渐变   01：拖尾   02：流水  03：追光  04:堆积  05:拉幕  06:流动   07：跑马）
      case '辅助按键':
        bytes = [0x7B, 0xFF, 0x11, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xBF];
        bytes[3] = data; //（0~3
      default:
        break;
    }
    return bytes;
  }

  static void send(String tag, var data) {
    List<int> bytes = getBytes(tag, data);
    print('自定义的类， 发送数据 = ${bytes.toHexstr(' |')}');
    if (bytes.isEmpty) {
      return;
    }
    BluetoothManager.instance.write(data: bytes, service_uuid: write_service, characteristics_uuid: write_char);
  }
}
